package com.wz.utils.concurrency.synchronizedlock;

import com.wz.utils.concurrency.cas.UnsafeFactory;
import sun.misc.Unsafe;

import java.nio.ByteOrder;

/**
 * @Author : Wang Zhen.
 * @Date : Created in 9:35 2022/11/5
 * @Description : x86一般是小端存储，高位字节在前，低位字节在后；大端反之
 * @Modified By   :
 * @Version :
 */
public class EndianTest {
    public static void main(String[] args) {
        Unsafe unsafe = UnsafeFactory.getUnsafe();
        long a = unsafe.allocateMemory(8);
        try {
            unsafe.putLong(a, 0x0102030405060708L);
            byte b = unsafe.getByte(a);
            ByteOrder byteOrder;
            switch (b) {
                case 0x01:
                    byteOrder = ByteOrder.BIG_ENDIAN;
                    break;
                case 0x08:
                    byteOrder = ByteOrder.LITTLE_ENDIAN;
                    break;
                default:
                    byteOrder = null;
            }
            System.out.println(byteOrder);
        } finally {
            unsafe.freeMemory(a);
        }
    }
}
